<?php
date_default_timezone_set('Asia/Shanghai');//时区配置
$conn=mysql_connect("localhost","root","");
include 'functions.php';
mysql_select_db("new_gsdai", $conn);
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn);

$time1 = strtotime(date('Y-m-d 10:00:00'));
$sql = "SELECT * FROM ych_borrow_tender WHERE borrow_id=2232 and add_time<$time1";
$result = db_fetch_arrays($sql, $conn);
foreach ($result as $key => $value){
	$account_result_reward 	= db_fetch_array("select * from ych_account where user_id={$value['user_id']}", $conn);
	$log['user_id'] 		= $value['user_id'];
	$log['ftype'] 			= 11;
	$log['money'] 			= round($value['account']*0.094, 2);
	$log['total'] 			= $account_result_reward['total']+$log['money'];
	$log['use_money'] 		= $account_result_reward['use_money']+$log['money'];
	$log['no_use_money'] 	= $account_result_reward['no_use_money'];
	$log['collection'] 		= $account_result_reward['collection'];
	$log['to_user'] 		= "3893";
	$log['remark'] 			= "借款[<a href=\'/borrow/obj/2232.html\'>信息技术公司新项目研发</a>]的奖励";
	$log['add_time'] 		= time();
	$log['addip'] 			= '127.0.0.1';
	$mode = $value['user_id']%100;
	$sql  ="insert into ych_account_log_$mode(user_id,ftype,total,money,use_money,no_use_money,
													collection,to_user,remark,add_time,addip) values( 
				 {$value['user_id']},{$log['ftype']},{$log['total']},{$log['money']},
				 {$log['use_money']},{$log['no_use_money']},
				 {$log['collection']},{$log['to_user']},'{$log['remark']}',
				 {$log['add_time']},'{$log['addip']}'
				 )";
	$query = mysql_query($sql, $conn);
	if(!$query){
		echo $sql;
		exit;
	}
	$query = mysql_query("update ych_account set total=total+{$log['money']},
				 use_money=use_money+{$log['money']} where user_id={$value['user_id']}", $conn);
	if(!$query){
		echo $sql;
		exit;
	}
				
	unset($account_result_reward);
	unset($log);			
	$account_result_reward 	= db_fetch_array("select * from ych_account where user_id=3893", $conn);
	$log['user_id'] 		= 3893;
	$log['ftype'] 			= 10;
	$log['money'] 			= round($value['account']*0.094, 2);
	$log['total'] 			= $account_result_reward['total']-$log['money'];
	$log['use_money'] 		= $account_result_reward['use_money']-$log['money'];
	$log['no_use_money'] 	= $account_result_reward['no_use_money'];
	$log['collection'] 		= $account_result_reward['collection'];
	$log['to_user'] 		= "1";
	$log['remark'] 			= "扣除借款[<a href=\'/borrow/obj/2232.html\'>信息技术公司新项目研发</a>]的奖励";
	$log['add_time'] 		= time();
	$log['addip'] 			= '127.0.0.1';
	$mode = 3893%100;
	$sql  ="insert into ych_account_log_$mode(user_id,ftype,total,money,use_money,no_use_money,
													collection,to_user,remark,add_time,addip) values( 
				 3893,{$log['ftype']},{$log['total']},{$log['money']},
				 {$log['use_money']},{$log['no_use_money']},
				 {$log['collection']},{$log['to_user']},'{$log['remark']}',
				 {$log['add_time']},'{$log['addip']}'
				 )";
	$query = mysql_query($sql, $conn);
	if(!$query){
		echo $sql;
		exit;
	}
	$query = mysql_query("update ych_account set total=total-{$log['money']},
				 use_money=use_money-{$log['money']} where user_id=3893", $conn);
	if(!$query){
		echo $sql;
		exit;
	}
	
}
